package com.mini.util;

import com.mini.constant.AllocationLevel;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * @author zhangxiaobin
 * @title: AllocationLevelConverter
 * @description: TODO
 * @date 2020/7/1711:39
 */
@Converter(autoApply = true)
public class AllocationLevelConverter implements AttributeConverter<AllocationLevel, Integer> {

    @Override
    public Integer convertToDatabaseColumn(AllocationLevel allocationLevel) {
        if(allocationLevel == null){
            return null;
        }
        return allocationLevel.getKey();
    }

    @Override
    public AllocationLevel convertToEntityAttribute(Integer val) {
        if(val == null){
            return null;
        }
        return AllocationLevel.parse(val);
    }
}
